package com.cipta.lomob.components;

import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Shader.TileMode;

import com.squareup.picasso.Transformation;

public class CropCircleTransformation implements Transformation {
	@Override
	public Bitmap transform(Bitmap source) {
		int size = Math.min(source.getWidth(), source.getHeight());
		Bitmap circleBitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);

		
		//use shader		
		BitmapShader shader = new BitmapShader (source,  TileMode.CLAMP, TileMode.CLAMP);

		Paint paint = new Paint();
		paint.setShader(shader);
		paint.setAntiAlias(true);
		//draw canvas
		Canvas c = new Canvas(circleBitmap);
		c.drawCircle(size/2, size/2, size/2, paint);
				
		if (circleBitmap != source) {
			source.recycle();
		}
		return circleBitmap;
	}

	@Override
	public String key() {
		return "circle()";
	}
}
